<?php
$sSQL = "
	SELECT
		pagina_id, parentid, titel
	FROM
		pagina
	WHERE
		active = 1
";

if ($_SESSION ['config'] ['register_login'] == 1)
{
	if (isset ($_SESSION ['username']))
	{
		$sSQL .= " AND `titel` != 'Registratie' ";
	}
	else
	{
		$sSQL .= " AND `titel` != 'Loguit' ";
	}
}
else
{
	$sSQL .= " AND `titel` != 'Registratie' AND `titel` != 'Loguit' ";
}

$sSQL .= " AND `titel` != 'Login' ORDER BY  pagina_id  ";

$sQuery = mysql_query($sSQL);

$GLOBALS['menuData'] = array(
	'items' => array(),
	'parents' => array()
);

while ($menuItem = mysql_fetch_assoc($sQuery))
{
	$GLOBALS['menuData']['items'][$menuItem['pagina_id']] = $menuItem;
	$GLOBALS['menuData']['parents'][$menuItem['parentid']][] = $menuItem['pagina_id'];
}

function bouwMenu($parentId, $menuData)
{
	global $_CONFIG;
    $html = '';

    if (isset($menuData['parents'][$parentId]))
    {
        $html = '<ul>';
        foreach ($menuData['parents'][$parentId] as $itemId)
        {
            $html .= '<li><a href="' . $_CONFIG['url'] . $menuData['items'][$itemId]['pagina_id'] . '/' . str_replace (' ', '_', $menuData['items'][$itemId]['titel']) . '.html" class="menu">' . $menuData['items'][$itemId]['titel'] . '</a>';
            $html .= bouwMenu($itemId, $menuData);
            $html .= '</li>';
        }
        $html .= '</ul>';
    }
    return $html;
}
?>
